package csc.fresher.domain;

// Generated Nov 5, 2014 8:56:03 PM by Hibernate Tools 3.4.0.CR1

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;

import static javax.persistence.GenerationType.IDENTITY;

import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;

import csc.fresher.customannotation.CardNumber;
import csc.fresher.customannotation.FirstLastName;
import csc.fresher.customannotation.LoginId;
import csc.fresher.customannotation.MidName;
import csc.fresher.customannotation.Phone1;
import csc.fresher.customannotation.Phone2;
import csc.fresher.customannotation.UniqueLoginId;

/**
 * Userinfo generated by hbm2java
 */
@Entity
@Table(name = "userinfo", catalog = "bankingsystemnew", uniqueConstraints = @UniqueConstraint(columnNames = "loginId"))
public class UserInfo implements java.io.Serializable {

	private Integer id;
	private Status status;
	private Role role;

	@Size(min = 5, message = "Username at least 5 characters")
	@LoginId
	@UniqueLoginId
	private String loginId;

	@Size(min = 8, message = "Password at least 8 characters")
	private String password;

	@CardNumber
	private String cardnumberid;

	@FirstLastName
	private String firstname;

	@FirstLastName
	private String lastname;

	@MidName
	private String midname;

	@Phone1
	private String phone1;

	@Phone2
	private String phone2;

	@NotEmpty(message = "Address not empty")
	private String address1;
	private String address2;

	@NotEmpty(message = "Email not empty")
	@Email(message = "Invalid Email")
	private String email1;

	@Email(message = "Invalid Email")
	private String email2;
	private byte[] image;
	private Set<History> histories = new HashSet<History>(0);

	public UserInfo() {
	}

	public UserInfo(Status status, Role role, String loginId, String password,
			String cardnumberid, String firstname, String lastname,
			String phone1, String address1, String email1) {
		this.status = status;
		this.role = role;
		this.loginId = loginId;
		this.password = password;
		this.cardnumberid = cardnumberid;
		this.firstname = firstname;
		this.lastname = lastname;
		this.phone1 = phone1;
		this.address1 = address1;
		this.email1 = email1;
	}

	public UserInfo(Status status, Role role, String loginId, String password,
			String cardnumberid, String firstname, String lastname,
			String midname, String phone1, String phone2, String address1,
			String address2, String email1, String email2, byte[] image,
			Set<History> histories) {
		this.status = status;
		this.role = role;
		this.loginId = loginId;
		this.password = password;
		this.cardnumberid = cardnumberid;
		this.firstname = firstname;
		this.lastname = lastname;
		this.midname = midname;
		this.phone1 = phone1;
		this.phone2 = phone2;
		this.address1 = address1;
		this.address2 = address2;
		this.email1 = email1;
		this.email2 = email2;
		this.image = image;
		this.histories = histories;
	}

	public UserInfo(Integer id, String loginId, Status status, Role role,
			String password, String cardnumberid, String firstname,
			String lastname, String midname, String phone1, String phone2,
			String address1, String address2, String email1, String email2,
			byte[] image) {
		super();
		this.id = id;
		this.status = status;
		this.role = role;
		this.loginId = loginId;
		this.password = password;
		this.cardnumberid = cardnumberid;
		this.firstname = firstname;
		this.lastname = lastname;
		this.midname = midname;
		this.phone1 = phone1;
		this.phone2 = phone2;
		this.address1 = address1;
		this.address2 = address2;
		this.email1 = email1;
		this.email2 = email2;
		this.image = image;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "statusid", nullable = false)
	public Status getStatus() {
		return this.status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	// Not using lazy loading because when authiry using
	// user.getRole().getRoleName()
	// using fetch.LAZY will error "No session"
	@ManyToOne
	@JoinColumn(name = "roleid", nullable = false)
	public Role getRole() {
		return this.role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	@Column(name = "loginId", unique = true, nullable = false, length = 45)
	public String getLoginId() {
		return this.loginId;
	}

	public void setLoginId(String loginId) {
		this.loginId = loginId;
	}

	@Column(name = "password", nullable = false, length = 500)
	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "cardnumberid", nullable = false, length = 45)
	public String getCardnumberid() {
		return this.cardnumberid;
	}

	public void setCardnumberid(String cardnumberid) {
		this.cardnumberid = cardnumberid;
	}

	@Column(name = "firstname", nullable = false, length = 45)
	public String getFirstname() {
		return this.firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	@Column(name = "lastname", nullable = false, length = 45)
	public String getLastname() {
		return this.lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	@Column(name = "midname", length = 45)
	public String getMidname() {
		return this.midname;
	}

	public void setMidname(String midname) {
		this.midname = midname;
	}

	@Column(name = "phone1", nullable = false, length = 11)
	public String getPhone1() {
		return this.phone1;
	}

	public void setPhone1(String phone1) {
		this.phone1 = phone1;
	}

	@Column(name = "phone2", length = 11)
	public String getPhone2() {
		return this.phone2;
	}

	public void setPhone2(String phone2) {
		this.phone2 = phone2;
	}

	@Column(name = "address1", nullable = false, length = 45)
	public String getAddress1() {
		return this.address1;
	}

	public void setAddress1(String address1) {
		this.address1 = address1;
	}

	@Column(name = "address2", length = 45)
	public String getAddress2() {
		return this.address2;
	}

	public void setAddress2(String address2) {
		this.address2 = address2;
	}

	@Column(name = "email1", nullable = false, length = 45)
	public String getEmail1() {
		return this.email1;
	}

	public void setEmail1(String email1) {
		this.email1 = email1;
	}

	@Column(name = "email2", length = 45)
	public String getEmail2() {
		return this.email2;
	}

	public void setEmail2(String email2) {
		this.email2 = email2;
	}

	@Column(name = "image")
	public byte[] getImage() {
		return this.image;
	}

	public void setImage(byte[] image) {
		this.image = image;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "userinfo")
	public Set<History> getHistories() {
		return this.histories;
	}

	public void setHistories(Set<History> histories) {
		this.histories = histories;
	}

}
